<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
	layout:decorator="v2/layout">
  <head>
    <title>欢迎进入管理系统</title>
    <script type="text/javascript" th:inline="javascript">
	    var serverH5Url = [[${application.serverH5Url}]];
    	var orgName = [[${session.user.name}]];
    	var state = getParam("state", "");
    	var evaluateId = getParam("evaluateId");
    	var type = getParam("type", "ZT");
    	var typeName = "";
    	if(type=='ZT'){
    		typeName = "文章";
    	} else if(type=='NOTICE'){
    		typeName = "公告";
    	} else if(type=='ZPQ'){
    		typeName = "照片墙";
    	} else if(type=='NEW'){
    		typeName = "外链";
    	}
    	
    	var listDel = function(id, text, state){
      		$.jjconfirm({text:text+"？",yes:function(){
      			$.ajaxData({url:"list-detailNewsSave",data:{id:id,state:state},type:"post",success:function(){
      				$("#listPage").pageReload();
      	  		}});
      		}});
      	}
    	
    	var addNews = function(){
      		$.listAlertData({ids:[],title:"选择"+typeName,data:{type:type},url:"/v2/plugin/news",cols:{"标题":"#{title}#","封面":'<img src="#{pic}#" height="60" class="article-cover"/>',"类型":"#{typeDesc}#"},success:function(r){
      			$.each(r, function(i,id){
      				$.ajaxData({url:"list-detailNewsSave",type:"post",data:{newsId:id,evaluateId:evaluateId,state:"LIVE"},success:function(){
        				$("#listPage").pageReload();
        			}});
      			});
      			
      	  	}});
      	}
      	var topNews = function(id, isTop){
      		$.ajaxData({url:"list-detailNewsSave",type:"post",data:{id:id,isTop:isTop},success:function(){
    			$("#listPage").pageReload();
    		}});
      	}
    	
    	$(function(){
    		setMenu("比赛资讯");
    		
    		$("#state li[data-state='"+type+"']").addClass("active")
    		$("#state li").click(function(){
    			location.href=setParam({type:$(this).data("state")})
    		});
    		
    		$("#listPage").page({url:"list-detailNewsList",data:{evaluateId:evaluateId,type:type}, success:function(ret){
      			$.each(ret.obj.content, function(i,v){
        			v.createdAt = new Date(v.createdAt).Format("yyyy-MM-dd HH:mm");
        			v.linkAt = new Date(v.linkAt).Format("yyyy-MM-dd HH:mm");
        		});
      			$("#list").loadData({content:ret.obj.content,orgName:orgName});
      		}});
    	});
    </script>
    <style>
    </style>
  </head>
  <body>
    <div layout:fragment="content">
    	<div class="c_tab">
   			<ul class="c_tab-list" id="state">
   				<li data-state="ZT">文章</li>
   				<li data-state="NOTICE">公告</li>
   				<li data-state="ZPQ">照片墙</li>
   				<li data-state="NEW">外链</li>
   			</ul>
    	</div>
    
		<div class="info info-full">
				<div class="detail-table">
       				<h4 class="detail-table-title">
						比赛资讯
						<button class="list-btn-item" style="float: right;" onclick="addNews();">关联</button>
					</h4>
				    <div class="table_list">
		               <div class="table-overflow">
		                   <table class="table">
		                       <thead>
			                       <tr>
			                       	 <th>内容</th>
			                       	 <th>类型</th>
	                                 <th>关联时间</th>
	                                 <th width="100">操作</th>
			                       </tr>
		                       </thead>
		                       <tbody>
		                       	<script type="text/template" id="list">
								#for(data:content)#
		                       	<tr>
									<td>
										#if(data.type!='NOTICE')# 
										<div class="article">
		                       				<img src="#{data.pic}#" class="article-cover"/>
		                       				<div class="article-info">
		                       					<div class="article-title">#{data.title}#</div>
		                       					<div class="article-time">
		                       						<span class="article-time-text">#{data.createdAt}#</span>
		                       					</div>
		                       				</div>
		                       			</div>
										#endif#
										#if(data.type=='NOTICE')# #{data.content}# #endif#
									</td>
									<td>#{data.typeDesc}#</td>
		                       		
									<td>
										#{data.linkAt}#
		                       		</td>
		                       		<td>
		                       			<div class="button">
		                       				<div class="button-item">
												#if(data.isTop)# <a href="javascript:topNews(#{data.id}#, false)">取消置顶</a> #endif#
												#if(!data.isTop)# <a href="javascript:topNews(#{data.id}#, true)">置顶</a> #endif#
											</div>
											<div class="button-item"><a href="javascript:listDel(#{data.id}#, '取消关联', 'DIE')">取消关联</a></div>
		                       			</div>
		                       		</td>
		                       	</tr>
								#endfor#
								</script>
		                     </tbody>
		                 </table>
		                 <div id="listPage"></div>
		             </div>
		          </div>
	          </div>
			
    	</div>
    	
    </div>
  </body>
</html>